README - SIMULATIONS

We aim to assess how clustered flags are. We calculated the distance between the flags we found in our fieldwork and the closest flag displayed on the same street. To determine how clustered or scattered they are, we conducted a hundred simulations of a random distribution of the same number of flags in the same street. A difference between the true, observed average distance and the averages obtained through the random simulations would inform about the existence of a behavioral pattern.

We employ two measures to calculate distances within streets: meters and street numbers. The rationale is the same. 

1. Step one is selecting all the streets in our sample where we found more than one flag in 2019. 

2. The second step is taking into account the number of flags in every street and its street numbers. This is the actual distribution of flags and will become our simulation no. 0. 

3. After that, we simulate a hundred random distributions of this amount of flags given the number of street numbers the street has to obtain of a hypothetical non-clustered or random distribution of these flags. These simulations do not consider the number of floors or apartments on every street. It assumes it resembles a normal distribution. 

4. Here’s where the two approaches diverge: 

4.1 For the meters analyses:

4.1.1 Then, we geocode every address/street number in each street. This piece of code is not provided as this part of the code was executed using the google maps API, which is not free anymore and requires registration. Only the output is provided. 

4.1.2 We merge these geocoded addresses with the street numbers of each simulation (incl. our real values, aka. Simulation no. 0). We use the geonear state package to calculate the distance to the nearest flag in each street within each simulation (incl. simulation no. 0). This package provides a distance in km. For instance, we found three flags in Concha Espina Ave. at numbers 4, 4, and 10, this package will inform us that we have two flags whose nearest neighbor is at 0 km., and one of the flags' nearest neighbor is at a distance of (I made this up) 0.2 km. 

4.2 For the street numbers analyses:

4.2.1 We calculate the difference in street numbers between each flag and the nearest neighboring flag in the same street. For instance, a flag whose nearest neighboring flag in the same street is also in the exact street number will obtain a value of 0. A flag on street number 20, whose nearest neighboring flag is displayed on st. number 55 will receive a value of 35. 

5. We have this information at the flag level and collapse it at the simulation level. This way, we obtain 101 observations per street. A hundred represent the average distance between n number of flags considering a random distribution of them. Another (simulation no. 0) provides the actual average distance between flags in this given street. 

6. We compare both real (simulation no. 0) vs. all the simulations to assess how different, and consequently, how clustered is the actual distribution of flags compared to the simulated or random one. 

------------------------------------------------------------
------------------------------------------------------------

Explanation with code at hand. 

Analyses calculating distance in meters.

1. Observe the number of flags in each street.

2. Simulate the distribution of these number of flags, with repetition possible—as in real life, flags can be in the same building/street number. 

3. Prepare the information to get the geolocation of those actual and simulated street numbers where x quantity of flags lie in a given street. These three steps are in: flags1_replication/Code/simulations/per_meters/There are two files for each street with more than one flag in our sample. This information is provided in the do file only detailing the name of the street, i.e., flags1_replication/Code/simulations/meters/per_meters/abtao.do

4. Once we identify each flag's longitude and latitude for each simulation and street, we calculate the distance between each flag and its closest neighbor. We append all these flag-level information about the closest neighboring flag in this street, including the real values (simulation no. 0) and all the simulations. This step is conducted separately for each street in all do files ending with `street’ n.do inside the folder flags1_replication/Code/simulations/per_meters/. I.e., flags1_replication/Code/simulations/meters/per_meters/abtao n.do

5. At this stage, we have all flag-level calculations of its nearest neighbor/flag within each simulation and street. It’s time to collapse them at the simulation level to compare the average distance of the real distribution of flags against all the simulated averages of these hypothetical random distributions of the number of flags. 
This step is implemented at do file flags1_replication/Code/simulations/meters/per_meters/appended_collapse_loop.do 

6. We empirically test the observability of clustering patterns in Table 2. This test is conducted through regression analyses comparing the real average distance between flags against the simulated ones. This step is at do file flags1_replication/Code/simulations/For_Table2_Col-3-4.do

7. A summary of this information is also provided in Figure 7. These plots show the percentile of the sampling simulated  distribution of the distance to the nearest flag in which the actual mean distance falls. The plot on the right side, corresponding to the analyses using meters distance, can be replicated using the code at flags1_replication/Code/simulations/meters/Figure7b.R

8. The more conservative version of this test conducted at the building/street number level follows the same pattern. Steps 1 to 4 are found conducted in one do file per street. All these do files can be found at the folder “flags1_replication/Code/simulations/meters/per_meters_one_flag_per_building/.” An instance of such would be “flags1_replication/Code/simulations/meters/per_meters_one_flag_per_building/abtao.do”

9. Programs executed for implementing steps 5 and 6 of these more conservative analyses of within-street flag clustering are conducted in the do file flags1_replication/Code/simulations/For_Table2_Col-7-8.do

------------------------------------------------------------


Analyses calculating distance in street numbers.

1. Observe the number of flags in each street.

2. Simulate the distribution of these number of flags, with repetition possible—as in real life, flags can be in the same building/street number. 

3. Put together all simulations with the real, observed distribution of flags in the street. These three steps are conducted separately for each street in all do files ending with `street’.do inside the folder flags1_replication/Code/simulations/per_meters/. I.e., flags1_replication/Code/simulations/street_number/per_street/abtao.do

4. At this stage, we have all flag-level calculations of its nearest neighbor/flag within each simulation and street. It’s time to collapse them at the simulation level to compare the average distance of the real distribution of flags against all the simulated averages of these hypothetical random distributions of the number of flags. This step is implemented at do file flags1_replication/Code/simulations/street_number/Figure7a.R 

5. We empirically test the observability of clustering patterns in Table 2. This test is conducted through regression analyses comparing the real average distance between flags against the simulated ones. This step is at do file flags1_replication/Code/simulations/For_Table2_Cols1-2_5-6.do

6. A summary of this information is also provided in Figure 7. These plots show the percentile of the sampling simulated  distribution of the distance to the nearest flag in which the actual mean distance falls. The plot on the right side, corresponding to the analyses using meters distance, can be replicated using the code at flags1_replication/Code/simulations/street_number/Figure7a.R

7. The more conservative version of this test conducted at the building/street number level follows the same pattern. Steps 1 to 3 are found conducted in one do file per street. All these do files can be found at the folder “flags1_replication/Code/simulations/street_number/per_street_one_flag_per_building/.” An instance of such would be “flags1_replication/Code/simulations/street_number/per_street_one_flag_per_building/abtao2.do”

8. Programs executed for implementing step 4 of these more conservative analyses of within-street flag clustering are conducted in the do file flags1_replication/Code/simulations/one_flag_per_building_preparing_dataset.do

9. This relatively more conservative estimate concerning flag clustering is also executed in flags1_replication/Code/simulations/For_Table2_Cols1-2_5-6.do 


